package priv.pront.code.lanqiao.competition.course.date0403;

import java.util.Scanner;

public class 开心的金明 {
    static int N,m;
    static int[] v,p,value;
    static int[][] dp;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt(); //  背包容量
        m = scanner.nextInt();  // 个数
        v = new int[m];
        p = new int[m];
        value = new int[m];
        dp = new int[m][N + 1];
        for (int i = 0; i < m; i++) {
            v[i] = scanner.nextInt();
            p[i] = scanner.nextInt();
            value[i] = v[i] * p[i];
        }

        for (int i = v[0]; i <= N; i++) {
            dp[0][i] = value[0];
        }

        for (int i = 1; i < m; i++) {
            for (int j = 0; j <= N; j++) {
                if(v[i] < j){
                    dp[i][j] = Math.max(dp[i - 1][j - v[i]] + value[i], dp[i - 1][j]);
                }else{
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        System.out.println(dp[m - 1][N]);

    }
}
